#ifndef __PORT_H__
#define __PORT_H__

#include <string>

#define ID_NOT_CHAR (0xFFFF)

typedef unsigned int TWCHAR;
typedef TWCHAR TWORDID;
typedef char* TIConvSrcPtr;

const TWORDID ID_NOT_WORD        = (0x0);
const TWORDID ID_UNKNOWN_CN      = (2);
const TWORDID ID_SEN_TOKEN       = (10);
const TWORDID ID_DIGIT           = (20);
const TWORDID ID_SIMBOL          = (21);
const TWORDID ID_DUMMY_WORD      = (69);
const TWORDID ID_NONWORD         = (69);
const TWORDID ID_ALLWORD         = (69);
const TWORDID ID_REALWORD_START  = (70);
const TWORDID ID_CNWORD_START    = (100);

const TWCHAR WCH_NULL          =  0;
const TWCHAR WCH_RETURN        =  '\n';
const TWCHAR WCH_TAB           =  '\t';
const TWCHAR WCH_SPACE         =  ' ';
const TWCHAR WCH_LESSTHAN      =  '<';
const TWCHAR WCH_GREATERTHAN   =  '>';

const TWCHAR WCH_DOUBLESPACE   =  0x3000;
const TWCHAR WCH_JUHAO         =  0x3002;
const TWCHAR WCH_WENHAO        =  0xFF1F;
const TWCHAR WCH_TANHAO        =  0xFF01;
const TWCHAR WCH_FENHAO        =  0xFF1B;
const TWCHAR WCH_MAOHAO        =  0xFF1A;
const TWCHAR WCH_DOUHAO        =  0xFF0C;
const TWCHAR WCH_ZUOKUOHAO     =  0x201C;
const TWCHAR WCH_YOUKUOHAO     =  0x201D;
const TWCHAR WCH_SHENGLUEHAO   =  0x2026;


// portable char type. it is UCS4 wide.
class TChar {
public:
  inline TChar() : m_ch(0)
  {}
  inline TChar(const TChar &r) : m_ch(r.m_ch)
  {}
  inline TChar(unsigned char c) : m_ch(c)
  {}
  inline TChar(const TWCHAR &wch) 
  {
    m_ch = (wch > ID_NOT_CHAR)?(ID_NOT_CHAR):(wch);
  }

  inline operator unsigned int(void) const 
  {
    return m_ch;
  }

  inline operator bool() const
  {
    return m_ch != 0;
  }
  
  inline TChar& operator=(const TChar &r)
  {
    m_ch = r.m_ch;
    return *this;
  }

  inline bool operator == (const TChar &r) const
  {
    return m_ch == r.m_ch;
  }
  
  inline bool operator != (const TChar &r) const
  {
    return m_ch != r.m_ch;
  }

  inline bool operator < (const TChar &r) const
  {
    return m_ch < r.m_ch;
  }
  inline bool operator > (const TChar &r) const
  {
    return m_ch > r.m_ch;
  }
  
  inline bool operator <= (const TChar &r) const
  {
    return m_ch <= r.m_ch;
  }
  inline bool operator >= (const TChar &r) const
  {
    return m_ch >= r.m_ch;
  }
  
private:
  unsigned short m_ch;
};

size_t MBSTOWCS(TWCHAR *pwcs, const char *s, size_t n);
size_t WCSTOMBS(char *s, const TWCHAR *pwcs, size_t n);
size_t WCSLEN(const TWCHAR *ws);

typedef std::basic_string<TWCHAR>   wstring;

#endif
